home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / hplip / fax / coverpages.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  12KB  |  398 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import warnings
  5. warnings.simplefilter('ignore', DeprecationWarning)
  6. warnings.simplefilter('ignore', SyntaxWarning)
  7. from reportlab.platypus.paragraph import Paragraph
  8. from reportlab.platypus.flowables import Preformatted, Image, HRFlowable
  9. from reportlab.platypus.doctemplate import *
  10. from reportlab.platypus import SimpleDocTemplate, Spacer
  11. from reportlab.platypus.tables import Table, TableStyle
  12. from reportlab.lib.pagesizes import letter, legal, A4
  13. from reportlab.lib.units import inch
  14. from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
  15. from reportlab.lib import colors
  16. from time import localtime, strftime
  17. warnings.simplefilter('default', DeprecationWarning)
  18. warnings.simplefilter('default', SyntaxWarning)
  19. if __name__ == '__main__':
  20.     import sys
  21.     sys.path.append('..')
  22.  
  23. from base.g import *
  24. from base import utils
  25. PAGE_SIZE_LETTER = 'letter'
  26. PAGE_SIZE_LEGAL = 'legal'
  27. PAGE_SIZE_A4 = 'a4'
  28.  
  29. def escape(s):
  30.     return s.replace('&', '&').replace('>', '>').replace('<', '<')
  31.  
  32.  
  33. def createStandardCoverPage(page_size = PAGE_SIZE_LETTER, total_pages = 1, recipient_name = '', recipient_phone = '', recipient_fax = '', sender_name = '', sender_phone = '', sender_fax = '', sender_email = '', regarding = '', message = '', preserve_formatting = False, output = None):
  34.     s = getSampleStyleSheet()
  35.     story = []
  36.     ps = ParagraphStyle(name = 'title', parent = None, fontName = 'helvetica-bold', fontSize = 72)
  37.     story.append(Paragraph('FAX', ps))
  38.     story.append(Spacer(1, inch))
  39.     ps = ParagraphStyle(name = 'normal', fontName = 'Times-Roman', fontSize = 12)
  40.     recipient_name_label = Paragraph('To:', ps)
  41.     recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
  42.     recipient_fax_label = Paragraph('Fax:', ps)
  43.     recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
  44.     recipient_phone_label = Paragraph('Phone:', ps)
  45.     recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
  46.     sender_name_label = Paragraph('From:', ps)
  47.     sender_name_text = Paragraph(escape(sender_name[:64]), ps)
  48.     sender_phone_label = Paragraph('Phone:', ps)
  49.     sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
  50.     sender_email_label = Paragraph('Email:', ps)
  51.     sender_email_text = Paragraph(escape(sender_email[:64]), ps)
  52.     regarding_label = Paragraph('Regarding:', ps)
  53.     regarding_text = Paragraph(escape(regarding[:128]), ps)
  54.     date_time_label = Paragraph('Date:', ps)
  55.     date_time_text = Paragraph(strftime('%a, %d %b %Y %H:%M:%S (%Z)', localtime()), ps)
  56.     total_pages_label = Paragraph('Total Pages:', ps)
  57.     total_pages_text = Paragraph('%d' % total_pages, ps)
  58.     data = [
  59.         [
  60.             recipient_name_label,
  61.             recipient_name_text,
  62.             sender_name_label,
  63.             sender_name_text],
  64.         [
  65.             recipient_fax_label,
  66.             recipient_fax_text,
  67.             sender_phone_label,
  68.             sender_phone_text],
  69.         [
  70.             date_time_label,
  71.             date_time_text,
  72.             sender_email_label,
  73.             sender_email_text],
  74.         [
  75.             regarding_label,
  76.             regarding_text,
  77.             total_pages_label,
  78.             total_pages_text]]
  79.     LIST_STYLE = TableStyle([
  80.         ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  81.         ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  82.     story.append(HRFlowable(width = '100%', color = 'black'))
  83.     story.append(Table(data, style = LIST_STYLE))
  84.     if message:
  85.         MSG_STYLE = TableStyle([
  86.             ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  87.             ('VALIGN', (0, 0), (-1, -1), 'TOP'),
  88.             ('SPAN', (-2, 1), (-1, -1))])
  89.         story.append(HRFlowable(width = '100%', color = 'black'))
  90.         story.append(Spacer(1, 0.5 * inch))
  91.         if preserve_formatting:
  92.             message = '\n'.join(message[:2048].splitlines()[:32])
  93.             data = [
  94.                 [
  95.                     Paragraph('Comments/Notes:', ps),
  96.                     ''],
  97.                 [
  98.                     Preformatted(escape(message), ps),
  99.                     '']]
  100.         else:
  101.             data = [
  102.                 [
  103.                     Paragraph('Comments/Notes:', ps),
  104.                     ''],
  105.                 [
  106.                     Paragraph(escape(message[:2048]), ps),
  107.                     '']]
  108.         story.append(HRFlowable(width = '100%', color = 'black'))
  109.         story.append(Table(data, style = MSG_STYLE))
  110.         story.append(HRFlowable(width = '100%', color = 'black'))
  111.     
  112.     if page_size == PAGE_SIZE_LETTER:
  113.         pgsz = letter
  114.     elif page_size == PAGE_SIZE_LEGAL:
  115.         pgsz = legal
  116.     else:
  117.         pgsz = A4
  118.     if output is None:
  119.         (f_fd, f) = utils.make_temp_file()
  120.     else:
  121.         f = output
  122.     doc = SimpleDocTemplate(f, pagesize = pgsz)
  123.     doc.build(story)
  124.     return f
  125.  
  126.  
  127. def createConfidentialCoverPage(page_size = PAGE_SIZE_LETTER, total_pages = 1, recipient_name = '', recipient_phone = '', recipient_fax = '', sender_name = '', sender_phone = '', sender_fax = '', sender_email = '', regarding = '', message = '', preserve_formatting = False, output = None):
  128.     s = getSampleStyleSheet()
  129.     story = []
  130.     story.append(Image(os.path.join(prop.image_dir, 'other', 'confidential_title.png')))
  131.     story.append(Spacer(1, inch))
  132.     story.append(HRFlowable(width = '100%', color = 'black'))
  133.     ps = ParagraphStyle(name = 'normal', fontName = 'Times-Roman', fontSize = 12)
  134.     recipient_name_label = Paragraph('To:', ps)
  135.     recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
  136.     recipient_fax_label = Paragraph('Fax:', ps)
  137.     recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
  138.     recipient_phone_label = Paragraph('Phone:', ps)
  139.     recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
  140.     sender_name_label = Paragraph('From:', ps)
  141.     sender_name_text = Paragraph(escape(sender_name[:64]), ps)
  142.     sender_phone_label = Paragraph('Phone:', ps)
  143.     sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
  144.     sender_email_label = Paragraph('Email:', ps)
  145.     sender_email_text = Paragraph(escape(sender_email[:64]), ps)
  146.     regarding_label = Paragraph('Regarding:', ps)
  147.     regarding_text = Paragraph(escape(regarding[:128]), ps)
  148.     date_time_label = Paragraph('Date:', ps)
  149.     date_time_text = Paragraph(strftime('%a, %d %b %Y %H:%M:%S (%Z)', localtime()), ps)
  150.     total_pages_label = Paragraph('Total Pages:', ps)
  151.     total_pages_text = Paragraph('%d' % total_pages, ps)
  152.     data = [
  153.         [
  154.             recipient_name_label,
  155.             recipient_name_text],
  156.         [
  157.             recipient_fax_label,
  158.             recipient_fax_text],
  159.         [
  160.             '',
  161.             ''],
  162.         [
  163.             sender_name_label,
  164.             sender_name_text],
  165.         [
  166.             sender_phone_label,
  167.             sender_phone_text],
  168.         [
  169.             sender_email_label,
  170.             sender_email_text],
  171.         [
  172.             '',
  173.             ''],
  174.         [
  175.             date_time_label,
  176.             date_time_text],
  177.         [
  178.             total_pages_label,
  179.             total_pages_text],
  180.         [
  181.             regarding_label,
  182.             regarding_text]]
  183.     LIST_STYLE = TableStyle([
  184.         ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  185.         ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  186.     story.append(Table(data, style = LIST_STYLE))
  187.     story.append(HRFlowable(width = '100%', color = 'black'))
  188.     if message:
  189.         MSG_STYLE = TableStyle([
  190.             ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  191.             ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  192.         story.append(Spacer(1, 0.5 * inch))
  193.         if preserve_formatting:
  194.             message = '\n'.join(message[:2048].splitlines()[:32])
  195.             story.append(Preformatted(escape(message), ps))
  196.         else:
  197.             story.append(Paragraph(escape(message), ps))
  198.     
  199.     if page_size == PAGE_SIZE_LETTER:
  200.         pgsz = letter
  201.     elif page_size == PAGE_SIZE_LEGAL:
  202.         pgsz = legal
  203.     else:
  204.         pgsz = A4
  205.     if output is None:
  206.         (f_fd, f) = utils.make_temp_file()
  207.     else:
  208.         f = output
  209.     doc = SimpleDocTemplate(f, pagesize = pgsz)
  210.     doc.build(story)
  211.     return f
  212.  
  213.  
  214. def createGenericCoverPage(page_size = PAGE_SIZE_LETTER, total_pages = 1, recipient_name = '', recipient_phone = '', recipient_fax = '', sender_name = '', sender_phone = '', sender_fax = '', sender_email = '', regarding = '', message = '', preserve_formatting = False, output = None):
  215.     s = getSampleStyleSheet()
  216.     story = []
  217.     i = Image(os.path.join(prop.image_dir, 'other', 'generic_title.png'), width = 250, height = 147)
  218.     i.hAlign = 'LEFT'
  219.     story.append(i)
  220.     story.append(HRFlowable(width = '100%', color = 'black'))
  221.     ps = ParagraphStyle(name = 'normal', fontName = 'Times-Roman', fontSize = 12)
  222.     recipient_name_label = Paragraph('To:', ps)
  223.     recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
  224.     recipient_fax_label = Paragraph('Fax:', ps)
  225.     recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
  226.     recipient_phone_label = Paragraph('Phone:', ps)
  227.     recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
  228.     sender_name_label = Paragraph('From:', ps)
  229.     sender_name_text = Paragraph(escape(sender_name[:64]), ps)
  230.     sender_phone_label = Paragraph('Phone:', ps)
  231.     sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
  232.     sender_email_label = Paragraph('Email:', ps)
  233.     sender_email_text = Paragraph(escape(sender_email[:64]), ps)
  234.     regarding_label = Paragraph('Regarding:', ps)
  235.     regarding_text = Paragraph(escape(regarding[:128]), ps)
  236.     date_time_label = Paragraph('Date:', ps)
  237.     date_time_text = Paragraph(strftime('%a, %d %b %Y %H:%M:%S (%Z)', localtime()), ps)
  238.     total_pages_label = Paragraph('Total Pages:', ps)
  239.     total_pages_text = Paragraph('%d' % total_pages, ps)
  240.     data = [
  241.         [
  242.             recipient_name_label,
  243.             recipient_name_text],
  244.         [
  245.             recipient_fax_label,
  246.             recipient_fax_text],
  247.         [
  248.             '',
  249.             ''],
  250.         [
  251.             sender_name_label,
  252.             sender_name_text],
  253.         [
  254.             sender_phone_label,
  255.             sender_phone_text],
  256.         [
  257.             sender_email_label,
  258.             sender_email_text],
  259.         [
  260.             '',
  261.             ''],
  262.         [
  263.             date_time_label,
  264.             date_time_text],
  265.         [
  266.             total_pages_label,
  267.             total_pages_text],
  268.         [
  269.             regarding_label,
  270.             regarding_text]]
  271.     LIST_STYLE = TableStyle([
  272.         ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  273.         ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  274.     story.append(Table(data, style = LIST_STYLE))
  275.     story.append(HRFlowable(width = '100%', color = 'black'))
  276.     if message:
  277.         MSG_STYLE = TableStyle([
  278.             ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  279.             ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  280.         story.append(Spacer(1, 0.5 * inch))
  281.         if preserve_formatting:
  282.             message = '\n'.join(message[:2048].splitlines()[:32])
  283.             story.append(Preformatted(escape(message), ps))
  284.         else:
  285.             story.append(Paragraph(escape(message), ps))
  286.     
  287.     if page_size == PAGE_SIZE_LETTER:
  288.         pgsz = letter
  289.     elif page_size == PAGE_SIZE_LEGAL:
  290.         pgsz = legal
  291.     else:
  292.         pgsz = A4
  293.     if output is None:
  294.         (f_fd, f) = utils.make_temp_file()
  295.     else:
  296.         f = output
  297.     doc = SimpleDocTemplate(f, pagesize = pgsz)
  298.     doc.build(story)
  299.     return f
  300.  
  301.  
  302. def createUrgentCoverPage(page_size = PAGE_SIZE_LETTER, total_pages = 1, recipient_name = '', recipient_phone = '', recipient_fax = '', sender_name = '', sender_phone = '', sender_fax = '', sender_email = '', regarding = '', message = '', preserve_formatting = False, output = None):
  303.     s = getSampleStyleSheet()
  304.     story = []
  305.     i = Image(os.path.join(prop.image_dir, 'other', 'urgent_title.png'), width = 424, height = 92)
  306.     i.hAlign = 'LEFT'
  307.     story.append(i)
  308.     story.append(Spacer(1, inch))
  309.     story.append(HRFlowable(width = '100%', color = 'black'))
  310.     ps = ParagraphStyle(name = 'normal', fontName = 'Times-Roman', fontSize = 12)
  311.     recipient_name_label = Paragraph('To:', ps)
  312.     recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
  313.     recipient_fax_label = Paragraph('Fax:', ps)
  314.     recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
  315.     recipient_phone_label = Paragraph('Phone:', ps)
  316.     recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
  317.     sender_name_label = Paragraph('From:', ps)
  318.     sender_name_text = Paragraph(escape(sender_name[:64]), ps)
  319.     sender_phone_label = Paragraph('Phone:', ps)
  320.     sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
  321.     sender_email_label = Paragraph('Email:', ps)
  322.     sender_email_text = Paragraph(escape(sender_email[:64]), ps)
  323.     regarding_label = Paragraph('Regarding:', ps)
  324.     regarding_text = Paragraph(escape(regarding[:128]), ps)
  325.     date_time_label = Paragraph('Date:', ps)
  326.     date_time_text = Paragraph(strftime('%a, %d %b %Y %H:%M:%S (%Z)', localtime()), ps)
  327.     total_pages_label = Paragraph('Total Pages:', ps)
  328.     total_pages_text = Paragraph('%d' % total_pages, ps)
  329.     data = [
  330.         [
  331.             recipient_name_label,
  332.             recipient_name_text],
  333.         [
  334.             recipient_fax_label,
  335.             recipient_fax_text],
  336.         [
  337.             '',
  338.             ''],
  339.         [
  340.             sender_name_label,
  341.             sender_name_text],
  342.         [
  343.             sender_phone_label,
  344.             sender_phone_text],
  345.         [
  346.             sender_email_label,
  347.             sender_email_text],
  348.         [
  349.             '',
  350.             ''],
  351.         [
  352.             date_time_label,
  353.             date_time_text],
  354.         [
  355.             total_pages_label,
  356.             total_pages_text],
  357.         [
  358.             regarding_label,
  359.             regarding_text]]
  360.     LIST_STYLE = TableStyle([
  361.         ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  362.         ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  363.     story.append(Table(data, style = LIST_STYLE))
  364.     story.append(HRFlowable(width = '100%', color = 'black'))
  365.     if message:
  366.         MSG_STYLE = TableStyle([
  367.             ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  368.             ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  369.         story.append(Spacer(1, 0.5 * inch))
  370.         if preserve_formatting:
  371.             message = '\n'.join(message[:2048].splitlines()[:32])
  372.             story.append(Preformatted(escape(message), ps))
  373.         else:
  374.             story.append(Paragraph(escape(message), ps))
  375.     
  376.     if page_size == PAGE_SIZE_LETTER:
  377.         pgsz = letter
  378.     elif page_size == PAGE_SIZE_LEGAL:
  379.         pgsz = legal
  380.     else:
  381.         pgsz = A4
  382.     if output is None:
  383.         (f_fd, f) = utils.make_temp_file()
  384.     else:
  385.         f = output
  386.     doc = SimpleDocTemplate(f, pagesize = pgsz)
  387.     doc.build(story)
  388.     return f
  389.  
  390. COVERPAGES = {
  391.     'basic': (createStandardCoverPage, 'standard_coverpage.png'),
  392.     'confidential': (createConfidentialCoverPage, 'confidential_coverpage.png'),
  393.     'generic': (createGenericCoverPage, 'generic_coverpage.png'),
  394.     'urgent': (createUrgentCoverPage, 'urgent_coverpage.png') }
  395. if __name__ == '__main__':
  396.     createUrgentCoverPage(page_size = PAGE_SIZE_LETTER, total_pages = 1, recipient_name = 'Trex', recipient_phone = '+1 234-567-8912', recipient_fax = '+1 432 123 1234', sender_name = 'Don', sender_phone = '+1 234 432 1234', sender_fax = '+1 567 876 5123 ', sender_email = 'test@hplip.sf.net', regarding = 'Some sorta stuff', message = 'Some HP printers require proprietary software technologies to allow full access to printer features and performance. These technologies cannot be open sourced. Because of this, HP uses a binary plug-in for these printers that work in conjunction with our Linux Open Source Printing Software to improve the printing experience for HP\xe2\x80\x99s Linux Printing Customers. This binary plug-in requires the user to read and agree to a license agreement at the time of driver installation.  There is a single plug-in file (for each HPLIP release) for all plug-in enabled devices.', preserve_formatting = False, output = 'output.pdf')
  397.  
  398.